package com.ruoyi.finance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.TSalaryBillInfo;
import com.ruoyi.finance.service.ITSalaryBillInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工资账单Controller
 * 
 * @author ruoyi
 * @date 2024-04-17
 */
@RestController
@RequestMapping("/finance/salary")
public class TSalaryBillInfoController extends BaseController
{
    @Autowired
    private ITSalaryBillInfoService tSalaryBillInfoService;

    /**
     * 查询工资账单列表
     */
    @PreAuthorize("@ss.hasPermi('finance:salary:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSalaryBillInfo tSalaryBillInfo)
    {
        startPage();
        List<TSalaryBillInfo> list = tSalaryBillInfoService.selectTSalaryBillInfoList(tSalaryBillInfo);
        return getDataTable(list);
    }

    /**
     * 导出工资账单列表
     */
    @PreAuthorize("@ss.hasPermi('finance:salary:export')")
    @Log(title = "工资账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSalaryBillInfo tSalaryBillInfo)
    {
        List<TSalaryBillInfo> list = tSalaryBillInfoService.selectTSalaryBillInfoList(tSalaryBillInfo);
        ExcelUtil<TSalaryBillInfo> util = new ExcelUtil<TSalaryBillInfo>(TSalaryBillInfo.class);
        util.exportExcel(response, list, "工资账单数据");
    }

    /**
     * 获取工资账单详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:salary:query')")
    @GetMapping(value = "/{salaryBillId}")
    public AjaxResult getInfo(@PathVariable("salaryBillId") Long salaryBillId)
    {
        return success(tSalaryBillInfoService.selectTSalaryBillInfoBySalaryBillId(salaryBillId));
    }

    /**
     * 新增工资账单
     */
    @PreAuthorize("@ss.hasPermi('finance:salary:add')")
    @Log(title = "工资账单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSalaryBillInfo tSalaryBillInfo)
    {
        tSalaryBillInfo.setCreateBy(getNickName());
        return toAjax(tSalaryBillInfoService.insertTSalaryBillInfo(tSalaryBillInfo));
    }

    /**
     * 修改工资账单
     */
    @PreAuthorize("@ss.hasPermi('finance:salary:edit')")
    @Log(title = "工资账单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSalaryBillInfo tSalaryBillInfo)
    {
        tSalaryBillInfo.setUpdateBy(getNickName());
        return toAjax(tSalaryBillInfoService.updateTSalaryBillInfo(tSalaryBillInfo));
    }

    /**
     * 删除工资账单
     */
    @PreAuthorize("@ss.hasPermi('finance:salary:remove')")
    @Log(title = "工资账单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{salaryBillIds}")
    public AjaxResult remove(@PathVariable Long[] salaryBillIds)
    {
        return toAjax(tSalaryBillInfoService.deleteTSalaryBillInfoBySalaryBillIds(salaryBillIds));
    }
}
